package pl.wroc.pwr.mss.server.ui.buttons;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import pl.wroc.pwr.mss.server.ui.dialogs.JSongPlaybackDialog;
import pl.wroc.pwr.mss.server.util.SongPlayback;

/**
 * Przycisk do zamykania okna dialogowego odtwarzania wybranego utworu.
 * 
 * @author mjagus
 */
public class JClosePlaybackDialogButton extends JButton implements ActionListener
{
    /**
     * Identyfikator klasy.
     */
    private static final long serialVersionUID = -2986311625248467310L;

    /**
     * Okno dialogowe odtwarzania wybranego utworu.
     */
    private JSongPlaybackDialog songPlaybackDialog;

    /**
     * Iniciuje komponent.
     */
    public JClosePlaybackDialogButton()
    {
        super("Close");
        super.addActionListener(this);
    }

    /**
     * @return Okno dialogowe odtwarzania wybranego utworu
     */
    public JSongPlaybackDialog getSongPlaybackDialog()
    {
        return songPlaybackDialog;
    }

    /**
     * @param songPlaybackDialog Okno dialogowe odtwarzania wybranego utworu
     */
    public void setSongPlaybackDialog(JSongPlaybackDialog songPlaybackDialog)
    {
        this.songPlaybackDialog = songPlaybackDialog;
    }

    @Override
    public void actionPerformed(ActionEvent e)
    {
        SongPlayback songPlayback = songPlaybackDialog.getSongPlayback();
        if(songPlayback != null)
            songPlayback.close();

        songPlaybackDialog.setVisible(false);
    }
}
